#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#include<stdlib.h>
#include<unistd.h>

int main()
{
	int fd1 = open("c.txt",O_RDWR);
	if(fd1==-1){
		perror("open");
		return -1;
	}

	printf("open successed,fd1 = %d\n",fd1);


	int fd3 = open("b.txt",O_RDWR);
	if(fd3==-1){
		perror("open");
		return -1;
	}

	printf("open successed,fd3 = %d\n",fd3);

	

	// 复 制 
	//int fd2 = dup(fd1);
	int fd2 = dup2(fd1,4);
	if(fd2==-1){
		perror("open");
		return -1;
	}
	printf("open successed,fd2 = %d\n",fd2);


	write(fd1,"000",3);
	//write(fd1,"abc",3);
	write(fd2,"wer",3);
	write(fd3,"happy",6);
	

	close(fd1);
	close(fd2);
	close(fd3);

	return 0;
}